package com.wunu.smartlock1

import android.app.Activity
import android.content.Intent
import com.billy.cc.core.component.CC
import com.billy.cc.core.component.CCResult
import com.billy.cc.core.component.IComponent
import com.wunu.smartlock1.activity.LockListActivity

/**
 * Created by peiwei on 2018/4/20.
 */
public class Component: IComponent {
    override fun getName(): String {
        return "wunu.smartlock"
    }

    override fun onCall(cc: CC?): Boolean {
        val actionName = cc?.actionName
        System.out.println(actionName)
        if (actionName != null && actionName!! == "showActivity") {
            openActivity(cc)
        }
        return false
    }
    private fun openActivity(cc: CC?) {
        val context = cc!!.context
        val intent = Intent(context, MainActivity::class.java)
        if (!(context is Activity)) {
            // 如果调用方没有设置context或app间组件跳转，则context为application
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        }
        context.startActivity(intent)
        CC.sendCCResult(cc.callId, CCResult.success())
    }

}